package com.wx.base.util;

import java.util.ArrayList;
import java.util.List;

import com.wx.base.util.cache.Wx_sys_persion_cache;
import com.wx.base.util.cache.Wx_sys_rpersion_cache;
import com.wx.base.util.cache.Wx_sys_urole_cache;
import com.wx.base.util.cache.Wx_sys_user_cache;
import com.wx.sys.entity.Wx_sys_persion;
import com.wx.sys.entity.Wx_sys_rpersion;
import com.wx.sys.entity.Wx_sys_urole;

public class UserUtil {
	// 用户权限缓存
	public static List<String> getUserStringPermission(String username) {
		long userId = Wx_sys_user_cache.getCache(username).getId();
		List<Wx_sys_urole> uroles = Wx_sys_urole_cache.getCaches();
		List<Wx_sys_rpersion> rpersions = Wx_sys_rpersion_cache.getCaches();
		List<Wx_sys_persion> persions = Wx_sys_persion_cache.getCaches();
		List<String> permissions = new ArrayList<String>();
		for (Wx_sys_urole wx_sys_urole : uroles) {
			if (wx_sys_urole.getUserId() == userId) {
				for (Wx_sys_rpersion wx_sys_rpersion : rpersions) {
					if (wx_sys_rpersion.getRoleId() == wx_sys_urole.getRoleId()) {
						for (Wx_sys_persion wx_sys_persion : persions) {
							if (wx_sys_persion.getId() == wx_sys_rpersion.getPerssionId()) {
								permissions.add(wx_sys_persion.getPersion());
							}
						}
					}
				}
			}
		}
		return permissions;
	}
}
